//
//  LWTextView.m
//  Message
//
//  Created by lzw on 2021/7/26.
//  Copyright © 2021 com.liu.message. All rights reserved.
//

#import "LWTextView.h"
#import "SCLTextView.h"
#import "UIColor+HEX.h"
#import "Masonry.h"
#import "SCLAlertView.h"

@interface LWTextView () <UITextFieldDelegate>


@end

@implementation LWTextView



#pragma mark - ***** 初始化 *****

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        self.layer.cornerRadius = 7;
        self.layer.masksToBounds = YES;
        self.backgroundColor = [UIColor colorWithHex:0x000000 andAlpha:0.8];
        
//        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(photoPreviewCollectionViewDidScroll:) name:@"InstallRefreshData" object:nil];
        
        [self initSubViews:frame];
    }
    return self;
}

- (void)initSubViews:(CGRect)frame {
    
    self.blurView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
//    self.blurView.alpha = 0.7;
    self.blurView.userInteractionEnabled = YES;
    self.blurView.frame = frame;
    [self addSubview:self.blurView];
 
    self.titLabe = [UILabel new];
    self.titLabe.textColor = [UIColor cyanColor];
    self.titLabe.font = [UIFont boldSystemFontOfSize:15];
    self.titLabe.textAlignment = 1;
    self.titLabe.text = @"请输入要搜索的数值";
    [self.blurView.contentView addSubview:self.titLabe];
    
    [self.titLabe mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.offset(0);
        make.top.offset(8);
        
    }];
    
    
    self.segmentedControl = [[UISegmentedControl alloc]initWithItems:@[@"I8",@"I16",@"I32",@"I64",@"F32",@"F64"]];
    self.segmentedControl.backgroundColor = [UIColor lightGrayColor];
    [self.blurView.contentView addSubview:self.segmentedControl];
    
    [self.segmentedControl mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.offset(4);
        make.right.offset(-4);
        make.top.offset(38);
        make.height.offset(35);
        
    }];
    
    self.textFileView = [[SCLTextView alloc] init];
    self.textFileView.placeholder = @"选择数据类型后输入搜索数值";
    self.textFileView.layer.cornerRadius = 7;
    self.textFileView.layer.masksToBounds = YES;
    self.textFileView.font = [UIFont systemFontOfSize:15];
    self.textFileView.layer.borderWidth = 1;
    self.textFileView.layer.borderColor = [UIColor whiteColor].CGColor;
    [self.blurView.contentView addSubview:self.textFileView];
    self.textFileView.delegate = self;
    
    [self.textFileView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.offset(8);
        make.right.offset(-8);
        make.top.offset(80);
        make.height.offset(34);
        
    }];

    
    self.doenBtn = [[UIButton alloc] init];
    self.doenBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
    [self.doenBtn setTitle:@"     确定     " forState:UIControlStateNormal];
    [self.doenBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.doenBtn addTarget:self action:@selector(doenBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    self.doenBtn.backgroundColor = [UIColor colorWithHexString:@"#696969"];
    self.doenBtn.layer.cornerRadius = 6;
    self.doenBtn.layer.masksToBounds = YES;
    
    
    [self.blurView.contentView addSubview:self.doenBtn];
    [self.doenBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.offset(-12);
        make.bottom.offset(-12);
        make.height.offset(32);
        
    }];
    
    self.cancelBtn = [[UIButton alloc] init];
    [self.cancelBtn setTitle:@"     取消     " forState:UIControlStateNormal];
    self.cancelBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
    [self.cancelBtn setTitleColor:[UIColor cyanColor] forState:UIControlStateNormal];
    
    self.cancelBtn.backgroundColor = [UIColor colorWithHexString:@"#696969"];
    self.cancelBtn.layer.cornerRadius = 6;
    self.cancelBtn.layer.masksToBounds = YES;
    
    
    [self.blurView.contentView addSubview:self.cancelBtn];
    [self.cancelBtn addTarget:self action:@selector(quxiaoBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.offset(12);
        make.bottom.offset(-12);
        make.height.offset(32);
        
    }];
    
}

- (void)doenBtnClick:(UIButton *)btn {
    
    if (self.segmentedControl.selectedSegmentIndex >= 0) {
        
        
    } else {
        
        SCLAlertView *alert =  [[SCLAlertView alloc] initWithNewWindow];
        
        
        [alert showInfo:@"温馨提示" subTitle:@"请选择要搜索的数据类型" closeButtonTitle:@"确定" duration:3];
        
        return;
    }
    
    if (self.doenBtnBlock) {
        
        NSString *indexStr = self.typeArr[self.segmentedControl.selectedSegmentIndex];
        
        NSArray *arr = @[indexStr,self.textFileView.text];
       
        self.doenBtnBlock(arr);
    }
    
}

- (void)quxiaoBtnClick:(UIButton *)btn {

    if (self.cancelBtnBlock) {
        
        self.cancelBtnBlock(@"");
    }
    
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {

    [[[UIApplication sharedApplication] keyWindow] endEditing:YES];

    return YES;
}

@end
